import request from "@/request";

/**
 * 测试网络是否联通, 这里顺便调用一个接口
 */
export const testNetInfo = () => {
  return request({
    url: "/api/device/api/sync/time",
    method: "GET",
    errShowMessage: false, // 不提示错误
    timeout: 10 * 1000
  });
};

/**
 * 检查设备的状态
 */
export const checkDeviceStatus = (params: { uuid?: string }) => {
  return request({
    url: "/api/device/api/check/auth",
    method: "GET",
    params
  });
};

/**
 * 获取时间
 */
export const getTime = () => {
  return request({
    url: "/api/device/api/sync/time",
    method: "GET"
  });
};

/**
 * 在线接口
 * 因为使用 websocket 来判断在线不稳定, 这里采用定时调用后台接口来判断设备是否在线
 */
export const online = () => {
  return request({
    url: "/api/device/api/judge/online",
    method: "GET",
    errShowMessage: false
  });
};

/**
 * 更新设备信息
 */
export const deviceUpdateVersion = (params: { deviceCode: string; version: string }) => {
  return request({
    url: "/api/device/api/update/version",
    method: "GET",
    params,
    errShowMessage: false
  });
};

/**
 * 查询离线未执行或者执行失败的指令
 * cmds: 则表示执行的命令码, 逗号分割
 */
export const listFailCmd = (deviceCode: string, cmds: string) => {
  return request({
    url: "/api/device/api/listFailCmd",
    method: "GET",
    params: {
      deviceCode,
      cmds
    },
    errShowMessage: false
  });
};

/**
 * 根据设备code获取设备信息
 */
export const getDeviceInfoByCode = (code: string) => {
  return request({
    url: "/api/device/api/getCode",
    method: "GET",
    params: {
      code
    },
    errShowMessage: false
  });
};